﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UserCenter.Models;

namespace UserCenter.Api.Tools
{
    public static class AuthUtils
    {
        public static DeviceType? ToDeviceType(uint deviceType)
        {
            if (deviceType > byte.MaxValue || deviceType < byte.MinValue)
            {
                return null;
            }
            else
            {
                var byteValue = Convert.ToByte(deviceType);
                if (Enum.IsDefined(typeof(AuthSource), byteValue))
                {

                    return (DeviceType)Enum.ToObject(typeof(AuthSource), byteValue);
                }
                else
                {
                    return null;
                }
            }
        }

        public static AuthSource? ToAuthSource(uint deviceType)
        {
            if (deviceType > byte.MaxValue || deviceType < byte.MinValue)
            {
                return null;
            }
            else
            {
                var byteValue = Convert.ToByte(deviceType);
                if (Enum.IsDefined(typeof(AuthSource), byteValue))
                {

                    return (AuthSource)Enum.ToObject(typeof(AuthSource), byteValue);
                }
                else
                {
                    return null;
                }
            }
        }
    }
}
